

-- Namespace
	local _,mod = ...


-- Locals
	local scale = .8
	
	local font = {mod.path..'media\\bavaria.ttf',8/scale,'OUTLINEMONOCHROME'}
	
	local c_border = {.07,.07,.07}


-- Destroy superfluous shit
	local function DESTROY()
		local destroy = {
			-- CURRENT WITH FRAMEXML AS OF: 5.0.4
			
			['GameTimeFrame'] = true,
			['GuildInstanceDifficulty'] = true,
			['MinimapBackdrop'] = true,
			['MinimapBorderTop'] = true,
			['MiniMapChallengeMode'] = true,
			['MiniMapInstanceDifficulty'] = true,
			['MiniMapMailFrame'] = true,
			['MiniMapVoiceChatFrame'] = true,
			['MinimapZoneTextButton'] = true,
			['TimeManagerClockButton'] = true,
		}
		
		MiniMapTrackingDropDown:SetParent(Minimap)
		QueueStatusMinimapButton:SetParent(Minimap)
		
		for frame in pairs(destroy) do
			frame = _G[frame]
			if frame then
				frame:Hide()
				hooksecurefunc(frame,'Show',frame.Hide)
			end
		end
		
		mod:event_unregister('PLAYER_ENTERING_WORLD',DESTROY)
	end
	mod:event_register('PLAYER_ENTERING_WORLD',DESTROY)


-- Shape standard
	function GetMinimapShape()
		return 'SQUARE'
	end


-- Skin
	Minimap:SetParent(UIParent)
	Minimap:ClearAllPoints()
	Minimap:SetPoint('TOPRIGHT',-14,-14)
	Minimap:SetScale(scale)
	Minimap:EnableMouse(true)
	Minimap:SetClampedToScreen(false)
	Minimap:SetMaskTexture('Interface\\Buttons\\WHITE8X8')
	Minimap:SetArchBlobRingScalar(0)
	Minimap:SetQuestBlobRingScalar(0)
	Minimap:SetQuestBlobRingAlpha(0)
	
	local border = Minimap:CreateTexture(nil,'BACKGROUND')
		border:SetPoint('TOPLEFT',(-1/scale),(1/scale))
		border:SetPoint('BOTTOMRIGHT',(1/scale),(-1/scale))
		border:SetTexture(unpack(c_border))
		Minimap.border = border


-- Coordinates
	local coordX = Minimap:CreateFontString(nil,'OVERLAY')
		coordX:SetPoint('BOTTOMRIGHT',Minimap,'BOTTOM',-6,4)
		coordX:SetFont(unpack(font))
		coordX:SetJustifyH('RIGHT')
		Minimap.coordX = coordX
	
	local coordY = Minimap:CreateFontString(nil,'OVERLAY')
		coordY:SetPoint('BOTTOMLEFT',Minimap,'BOTTOM',6,4)
		coordY:SetFont(unpack(font))
		coordY:SetJustifyH('LEFT')
		Minimap.coordY = coordY
	
	mod:timer_register(.1,true,function()
		local x,y = GetPlayerMapPosition('player')
		x,y = x*100,y*100
		coordX:SetText(('%.1f'):format(x))
		coordY:SetText(('%.1f'):format(y))
	end)


-- Scrolling
	Minimap:EnableMouseWheel(true)
	Minimap.EnableMouseWheel = function() end
	Minimap:SetScript('OnMouseWheel',function(self,delta)
		local zoom = self:GetZoom() + delta
		if zoom > 5 then
			zoom = 5
		elseif zoom < 0 then
			zoom = 0
		end
		self:SetZoom(zoom)
	end)


-- Tracking dropdown
	local old = Minimap:GetScript('OnMouseUp')
	Minimap:SetScript('OnMouseUp',function(self,btn,...)
		if btn == 'RightButton' then
			ToggleDropDownMenu(1,nil,MiniMapTrackingDropDown,'cursor')
		else
			return old(self,btn,...)
		end
	end)
